package com.smartEdu.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.controller.app.AppBaseController;
import com.smartEdu.exception.ServiceException;
import com.smartEdu.response.Response;
import com.smartEdu.service.UserService;
import com.smartEdu.utils.JsonUtil;

@Controller
public class UserInfoController  extends AppBaseController {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	@Qualifier(value="appresponse")
	public Response respContext;
	
	@RequestMapping(value="/checkUserInfo", method = RequestMethod.POST)
	public void checkUserInfo(HttpServletRequest request,HttpServletResponse response) {
		Session sess=null;
		InitSession(request);
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			Map<String, Object> map = JsonUtil.toMap(sess.gets(Tag_Tips.REQUEST));
			userService.checkUserInfo(sess,map.get("id").toString(),map.get("pwd").toString());
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}

	@Override
	public String GetRespContent(Session sess) {
		return respContext.GetRespContent(sess);
	}
	
	public void InitSession(HttpServletRequest request){
		Session sess=new Session();
		request.setAttribute("sess", sess);
	}
}
